<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <a-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目单号">
              <a-input placeholder="请输入项目单号" v-model="queryParam.itembh"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目单状态">
              <j-dict-select-tag type="list" v-model="queryParam.status" dictCode="xmd_status" placeholder="请选择项目单状态"/>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="3" :lg="7" :md="5" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--  <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--  <i style="margin-left: 26px;"></i> 累计完成的结算金额为 <a style="font-weight: 600">{{ jsjeSum }}</a>元-->
      <!--  <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--</div>-->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="record.status == 5"  @click="handleAudit(record,1)">阶段验收</a>
           <a-divider type="vertical" v-if="record.status == 5"></a-divider>
          <a v-if="record.status == 5"  @click="handleAudit(record,0)">完工验收</a>
          <!--<a v-if="record.status == 5"  @click="handleAudit(record)">验收</a>-->
          <a v-if="record.status != 5" @click="handleDetail(record)">详情</a>
          <!--<a-divider type="vertical" v-if="record.status > 5"></a-divider>-->
          <!--<a v-if="record.status > 5" @click="viewYsd(record)">验收单</a>-->
        </span>
      </a-table>
    </div>

    <a-modal
      title="查看验收单"
      :visible="visibleHz"
      width="1000px"
      cancelText="关闭"
      @cancel="HzClose"
      :okButtonProps="{ class:{'jee-hidden': true} }"
    >
      <div  id="hz" style="width:960px;height:600px;">
        <iframe style="width: 100%;height: 100%;" :src="hzImgUrl"></iframe>
      </div>
    </a-modal>

    <cus-ys-project-modal ref="modalForm" @ok="modalFormOk"></cus-ys-project-modal>
  </a-card>
</template>

<script>

  import { httpAction, getAction, postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CusYsProjectModal from './modules/CusYsProjectModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

  export default {
    name: 'CusYsProjectList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      CusYsProjectModal,
    },
    data () {
      return {
        description: '待验收项目单列表',
        queryParam: {
          xmmc: '',
          xmbh: '',
          status: '',
          itembh: '',
          name: '',
        },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
                return parseInt(index)+1;
            }
          },
          {
            title:'项目编号',
            align:"center",
            dataIndex: 'xmbh'
          },
          {
            title:'项目协议编号',
            align:"center",
            dataIndex: 'xmxybh'
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'xmmc'
          },
          {
            title:'项目单号',
            align:"center",
            dataIndex: 'itembh'
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'身份证号',
            align:"center",
            dataIndex: 'identityid'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'phone'
          },
          // {
          //   title:'任务金额',
          //   align:"center",
          //   dataIndex: 'rwje'
          // },
          {
            title:'提交验收时间',
            align:"center",
            dataIndex: 'wctime',
            customRender:function (t,r,index) {
              if(r.status < 3){
                return "-";
              } else {
                return t;
              }
            }
          },
          {
            title:'结算金额',
            align:"center",
            dataIndex: 'fkje',
            customRender:function (t,r,index) {
              if(r.status < 3){
                return "-";
              } else {
                return t;
              }
            }
          },
          {
            title:'项目单状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:87,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/project/lhygProjectIndividual/list",
        },
        dictOptions:{},
        jsjeSum: 0,
        jsdh: '',
        jsje: '',
        fwfje: '',
        zje: '',
        ptzhm: '',
        ptkhh: '',
        ptkh: '',
        qykhh: '',
        qykh: '',
        visibleHz: false,
        hzImgUrl: '',
      }
    },
    created() {
    },
    computed: {
    },
    methods: {
      initDictConfig(){
      },
      handleAudit(record,ystype){
        record.ystype = ystype;
        this.$refs.modalForm.audit(record);
        this.$refs.modalForm.title = "验收";
        this.$refs.modalForm.disableSubmit = false;
      },
      onSelectChange(selectedRowKeys, selectionRows) {
          this.selectedRowKeys = selectedRowKeys;
          this.selectionRows = selectionRows;
          let fkjeSum = 0
          selectionRows.forEach((item,i) => {
              if(item.status == 8) {
                fkjeSum = parseFloat(fkjeSum) + parseFloat(item.fkje);
              }
          })
          this.jsjeSum = fkjeSum.toFixed(2);
      },
      onClearSelected() {
          this.jsjeSum = 0;
          this.selectedRowKeys = [];
          this.selectionRows = [];
      },
      viewYsd(record){
          this.hzImgUrl = record.ysdpdf;
          this.visibleHz = true;
      },
      HzClose(){
          this.visibleHz = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>